package microservices.spring_cloud_server.rest;

import java.util.List;

import javax.ws.rs.PathParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import microservices.spring_cloud_server.dao.RoleDao;
import microservices.spring_cloud_server.dao.UserDao;
import microservices.spring_cloud_server.vo.PageVO;
import microservices.spring_cloud_server.vo.PagedResult;
import microservices.spring_cloud_server.vo.RoleVO;
import microservices.spring_cloud_server.vo.UserVO;

@RestController
public class UserService {
	@Autowired
	UserDao userDao;
	@Autowired
	RoleDao roleDao;

	@RequestMapping(value = "/userquery/{pageSize}/{pageNo}", method = RequestMethod.POST)
	public PagedResult<UserVO> queryUserPagedList(@RequestBody UserVO userVO,
			@PathParam(value = "pageVO") PageVO pageVO) throws InterruptedException { 
		return userDao.queryUserPagedList(userVO, pageVO);
	}

	@RequestMapping(value = "/useradd", method = RequestMethod.POST)
	public void insertUser(@RequestBody UserVO userVO) {
		userDao.addUser(userVO);
	}

	@RequestMapping(value = "/userdelete", method = RequestMethod.POST)
	public void batchDeleteUser(@RequestBody List<UserVO> userList) {
		userDao.batchDeleteUser(userList);
	}

	@RequestMapping(value = "/userupdate", method = RequestMethod.POST)
	public void updateUser(@RequestBody UserVO userVO) throws InterruptedException {
		userDao.updateUser(userVO);
	}

	@RequestMapping(value = "/getrole", method = RequestMethod.POST)
	public List<RoleVO> getRole() {
		List<RoleVO> roleLists = roleDao.queryRole();
		return roleLists;
	}

}
